//
//  VideoTableViewCell.m
//  HelpThePoor
//
//  Created by van7ish on 2016/12/6.
//  Copyright © 2016年 van7ish. All rights reserved.
//

#import "VideoTableViewCell.h"

#define cellHeight HeightScale(145)

@implementation VideoTableViewCell

- (UIImageView *)coverImageView{
    if (!_coverImageView) {
        _coverImageView = [[UIImageView alloc] initWithFrame:CGRectMake(WidthScale(10), HeightScale(15), (cellHeight - WidthScale(40)) * 1.5, cellHeight - HeightScale(40))];
        _coverImageView.layer.cornerRadius = WidthScale(8);
        _coverImageView.layer.masksToBounds = YES;
    }
    return _coverImageView;
}

- (UIImageView *)playImageView{
    if (!_playImageView) {
        _playImageView = [[UIImageView alloc] initWithFrame:CGRectMake(WidthScale(5), self.coverImageView.frame.size.height - HeightScale(20), WidthScale(16), HeightScale(15))];
        _playImageView.image = ImageNamed(@"video");
    }
    return _playImageView;
}

- (UILabel *)countLabel{
    if (!_countLabel) {
        _countLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.playImageView.frame) + WidthScale(5), self.playImageView.frame.origin.y, self.coverImageView.frame.size.width - WidthScale(30), HeightScale(15))];
        _countLabel.textColor = COLOR_WHITE;
        _countLabel.font = FONTSIZE(13);
    }
    return _countLabel;
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.coverImageView.frame) + WidthScale(15), self.coverImageView.frame.origin.y, SCREEN_W - CGRectGetMaxX(self.coverImageView.frame) - WidthScale(30), HeightScale(30))];

        _titleLabel.font = FONTSIZE(17);
    }
    return _titleLabel;
}

- (UIImageView *)authorImageView{
    if (!_authorImageView) {
        _authorImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.titleLabel.frame.origin.x, CGRectGetMaxY(self.coverImageView.frame) -   HeightScale(16.25), WidthScale(12.5), HeightScale(12.5))];
        _authorImageView.image = ImageNamed(@"people");
    }
    return _authorImageView;
}

- (UILabel *)authorLabel{
    if (!_authorLabel) {
        _authorLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.authorImageView.frame) + WidthScale(5), CGRectGetMaxY(self.coverImageView.frame) - HeightScale(20), WidthScale(110), HeightScale(20))];
        _authorLabel.font = FONTSIZE(13);
        _authorLabel.textColor = COLOR_FONTLIGHTGRAY;
    }
    return _authorLabel;
}

- (UILabel *)descLabel{
    if (!_descLabel) {
        _descLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.titleLabel.frame.origin.x, CGRectGetMaxY(self.titleLabel.frame), self.titleLabel.frame.size.width, self.coverImageView.frame.size.height - self.titleLabel.frame.size.height - self.authorLabel.frame.size.height)];
        _descLabel.numberOfLines = 0;
        _descLabel.font = FONTSIZE(15);
        _descLabel.textColor = COLOR_FONTLIGHTGRAY;
    }
    return _descLabel;
}

- (UIView *)underLine{
    if (!_underLine) {
        _underLine = [[UIView alloc] initWithFrame:CGRectMake(WidthScale(10), cellHeight - 0.5, SCREEN_W - WidthScale(10) * 2, 0.5)];
        _underLine.backgroundColor = COLOR_GRAYLINE;
    }
    return _underLine;
}

- (UIImageView *)timeImageView{
    if (!_timeImageView) {
        _timeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_W - WidthScale(107.5), self.authorImageView.frame.origin.y, self.authorImageView.frame.size.width, self.authorImageView.frame.size.height)];
        _timeImageView.image = ImageNamed(@"time");
    }
    return _timeImageView;
}

- (UILabel *)timeLabel{
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.timeImageView.frame) + WidthScale(5), self.authorLabel.frame.origin.y, WidthScale(80), self.authorLabel.frame.size.height)];
        _timeLabel.font = FONTSIZE(13);
        _timeLabel.textColor = COLOR_FONTLIGHTGRAY;
    }
    return _timeLabel;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    self.contentView.backgroundColor = COLOR_LIGHTBGCOLOR;
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    [self.contentView addSubview:self.coverImageView];
    [self.coverImageView addSubview:self.playImageView];
    [self.coverImageView addSubview:self.countLabel];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.descLabel];
    [self.contentView addSubview:self.authorImageView];
    [self.contentView addSubview:self.authorLabel];
    [self.contentView addSubview:self.underLine];
    [self.contentView addSubview:self.timeImageView];
    [self.contentView addSubview:self.timeLabel];
    
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
